package cn.itcast.mq.listener;

import cn.itcast.mq.config.CommonConfig;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

@Component
public class SpringRabbitListener {

    @RabbitListener(queues = CommonConfig.DIRECT_QUEUE)
    public void listenMessage(String msg) {
        System.out.println("消费者接收到simple.queue的消息：【" + msg + "】");
        int i=1/0;
        System.out.println("消息处理成功");
    }
    @RabbitListener(bindings =@QueueBinding(value = @Queue(name = "error.queue"),exchange =@Exchange(name="error.exchange"),key ="error.key"))
    public void errorMessage(String errorMsg){
        System.out.println("错误重试机制开启后，收到的消息:"+errorMsg);
    }
    @RabbitListener(bindings =@QueueBinding(value = @Queue(name = "ttl.queue"),exchange =@Exchange(name="ttl.exchange"),key ="ttl.key"))
    public void ttlMessage(String ttlMsg){
        System.out.println("延迟机制，收到的消息:"+ttlMsg);
    }
    @RabbitListener(bindings =@QueueBinding(value = @Queue(name = "delay.queue"),exchange =@Exchange(name="delay.exchange",delayed = "true"),key ="delay.key"))
    public void delayMessage(String ttlMsg){
        System.out.println("延迟交换机，收到的消息:"+ttlMsg);
    }
    @RabbitListener(queuesToDeclare = @Queue(name = "lazy.queue2",durable = "true",arguments = @Argument(name = "x-queue-mode",value = "lazy")))
    public void lazyMessage(String ttlMsg){
        System.out.println("惰性队列，收到的消息:"+ttlMsg);
    }
}
